﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Core.Dao;
using Core.Entity;
using System.Data;

namespace Core.Business
{
    public class DepartmentBus
    {
        private DepartmentDao dao;
        public DepartmentBus()
        {
            dao = new DepartmentDao();
        }

        public bool insert(Department department) {
            return dao.insert(department);
        }

        public bool update(Department department) {
            return dao.update(department);
        }

        public bool delete(int id) {
            return dao.delete(id);
        }

        public bool delete(String ids) {
            return dao.delete(ids);
        }

        public Department get(int id) {
            DataTable dt = dao.get(id);
            Department department = new Department();

            if (dt.Rows.Count > 0)
            {
                department.Id = Convert.ToInt32(dt.Rows[0]["DEP_ID"]);
                department.Name = dt.Rows[0]["DEP_NAME"].ToString();
                department.Desc = dt.Rows[0]["DEP_DESC"].ToString();
            }
            return department;
        }

        public List<Department> getAll() {
            DataTable dt = dao.getAll();
            List<Department> list = new List<Department>();

            if (dt.Rows.Count > 0)
            {
                foreach (DataRow dr in dt.Rows)
                {
                    Department department = new Department();
                    department.Id = Convert.ToInt32(dr["DEP_ID"]);
                    department.Name = dr["DEP_NAME"].ToString();
                    department.Desc = dr["DEP_DESC"].ToString();

                    list.Add(department);
                }

            }
            return list;
        }
    }
}
